<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class main extends CI_Controller {

	private $all_session;
	private $id;
	private $data;

	public function __construct()
    {
        parent::__construct();

        @$this->all_session = $this->session->all_userdata();  
        @$this->id = $this->all_session['login'][0]['mem_id'];    
    }

	public function index()
	{		
		
		$this->data['member'] = $this->main_model->get_member($this->id);		
		$this->data['web_service'] = $this->main_model->get_web_service();
		$this->data['new_vdo'] = $this->main_model->new_vdo();		
		$this->data['category_id'] = $this->main_model->get_category();
		for($i=0;$i<count($this->data['category_id']);$i++)
		{
			$this->data['new_category'][$i] = $this->main_model->new_category($this->data['category_id'][$i]['category_id']);
		}
		$this->data['slide'] = $this->main_model->get_slide();
		$this->data['my_favorite'] = $this->main_model->get_favorite($this->id);
		$this->data['top_view'] = $this->main_model->get_top_view();
		$this->data['top_like'] = $this->main_model->get_top_like();

		$this->check_slidetime();

		$this->load->view('main',$this->data);

	}

	public function check_slidetime()
	{
		$data['slide'] = $this->main_model->get_slide();

		$count = count($data['slide']);
	
		date_default_timezone_set("Asia/Bangkok");
		$now = date("Y-m-d");

		for($i=0;$i<$count;$i++)
		{		
			$exp = (strtotime($data['slide'][$i]['slide_end']) - strtotime($now))/  ( 60 * 60 );

			if($exp < 0)
			{
				$input = array(
					'vdo_id' => $data['slide'][$i]['vdo_id'],
					'slide_status' => 0
				);
				$this->slide_model->update_slide($input);
			}
			

		}

	

	}

	
}